/*
 * 导入外部js文件
 */
document.write("<script language=javascript src='/js/common.js'></script>");
var passwordPattern = /^((?=.*\d)(?=.*\D)|(?=.*[a-zA-Z])(?=.*[^a-zA-Z]))^.{8,16}$/;
var error = true;

function checkPassword(password){
	var msg = document.getElementById("newError");
	if(!passwordPattern.test(password)){
		error = true;
		msg.innerHTML = "请输入至少8位包含两种字符的密码";
		return ;
	}
	error = false;
	msg.innerHTML = "";
	var ensure = document.getElementById("ensure").value;
	if(ensure!=""){
		checkEnsure(ensure);
	}
};

function checkEnsure(password){
	var nPass = document.getElementById("new").value;
	var msg = document.getElementById("ensureError");
	if(nPass!=password){
		error = true;
		msg.innerHTML = "两次密码输入不正确";
		return ;
	}
	error = false;
	msg.innerHTML = "";
};

function checkNsubmit(){
	if(error){
		return ;
	}
	var oldP = document.getElementById("old").value;
	var newP = document.getElementById("new").value;
	ajax({
		url: "/user/password/modify",
		method: "POST",
		data: "newPassword="+newP+"&oldPassword="+oldP,
		onsuccess: function(text){
			var result = eval("("+text+")");
			if(!result.success){
				document.getElementById("oldError").innerHTML= result.params.error;
			}else{
				document.getElementById("oldError").innerHTML= "密码修改成功";
				window.location.reload();
			}
		}
	});
}